package com.topscomm.main.config;

import com.topscomm.basic.util.Config;
import com.topscomm.pub.util.SecurityUtil;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;

/**
 * @author wudaliang
 * @date 2022/7/2
 * @description: Redis配置
 * @modify:
 */
public class LocalRedisProperties extends RedisProperties {

    @Override
    public void setPassword(String password) {
        super.setPassword(decryptString(password));
    }

    @Override
    public void setHost(String host) {
        super.setHost(decryptString(host));
    }

    private synchronized String decryptString(String encryptedString) {
        String isEncrypt = Config.getInstance().getValue("IsRedisEncrypt");
        if (isEncrypt.equalsIgnoreCase("true")) {
            String plainString = encryptedString;
            if (plainString != null && plainString.trim().length() > 0) {
                plainString = SecurityUtil.decryptDes(plainString.trim(), "topscommkey");
            }
            return plainString;
        } else {
            return encryptedString;
        }
    }
}
